package com.qfjg.webcore;

import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.MemcachedClientBuilder;
import net.rubyeye.xmemcached.XMemcachedClientBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class MemcachedConfig {
    @Value("${memcached.servers}")
    private String servers;
    @Value("${memcached.timeout}")
    private long timeout;
    @Value("${memcached.poolSize}")
    private int poolSize;
    @Bean
    public MemcachedClient getMemcachedClient() throws IOException {
        MemcachedClientBuilder memcachedClientBuilder = new XMemcachedClientBuilder(servers);
        memcachedClientBuilder.setConnectionPoolSize(poolSize);
        memcachedClientBuilder.setOpTimeout(timeout);
        MemcachedClient memcachedClient = memcachedClientBuilder.build();
        return memcachedClient;
    }
}
